import { Authorized,HeaderParam,Get,JsonController,QueryParams,UseBefore,UseInterceptor,Post,Body} from "routing-controllers";
import { getOneUser ,addUser} from "../../model/request/User";
import { RequestLog } from "../../middledware/requestLog";
import { Service,Inject, } from "typedi";
import { UserServiceimpl } from "../../service/impl/userServiceimpl";
import { User } from "../../model/response/user";
import { JsonResponse } from "../../middledware/JsonResponse"
import { JsonResult ,msgList,res} from "../../utils/jsonResult";
import  config from "@/config/init";
import  {Token} from "@/m_req/request_Token";




 @Service()
 @JsonController(config.setPrefix("app/user"))
export class indexController{

    @Inject()
    UserServiceimpl!:UserServiceimpl;
    
    @Inject()
    jsonResult!:JsonResult<any>

    // @Post('/info')
    // @UseBefore(RequestLog)
    // @Authorized()
    // async getOneUser(@HeaderParam("token") token: Token): Promise<res<User | null>>{
    //   console.log("token: ", token);
    //   return await this.UserServiceimpl.GetOneUser(token.user_id);
    // }
  
    //用户添加
  @Post('/add')
  @UseBefore(RequestLog)
  async add(@Body() params: addUser):Promise<res<null>> {
    console.log("params",params)
    return await this.UserServiceimpl.addUser(params);
    
  }
  //登录
  
  @Post('/login')
  @UseBefore(RequestLog)
  async Login(@Body() params: addUser): Promise<res<User | null>> {
    return await this.UserServiceimpl.Login(params);
  }
  
}